/*****************************************************************//**
 * \file   AnsysAPDLReaderBase.h
 * \brief  AnsysAPDLReaderBase
 *
 * \author Wyatt
 * \date   May 2023
 *********************************************************************/
#pragma once

#include <string>

#include "AnsysDef.h"
#include "AnsysReaderMgr.h"

class CDBReader;
class ReaderBase
{
public:
	ReaderBase(CDBReader* pCDBReader);
	virtual ~ReaderBase(void);

	virtual ANSYS_KEYWORD GetKeyWord();
	virtual CDBReader* GetCDBReader() final;
	virtual std::string GetReaderName();
	virtual void destroy_instance();
	virtual void update_instance();

	virtual bool Scan(std::string& dataLine);
	virtual bool Read(std::string& dataLine);

	virtual bool clear_map();
	enum InBlockTag
	{
		IN_NONE = 0,
		IN_YES,
	};
	virtual InBlockTag InBlock() { return _inBlock; }

	virtual long Build() { return 0; }

protected:
	CDBReader* _pCDBReader{};
	InBlockTag _inBlock = IN_NONE;

};

//void update_instance();
//void class_name::update_instance() {if(_instance){_instance = new class_name(CDBReader::Inst());}}

#define DECLARE_CDB_READER(class_name)                                                              \
public:                                                                                             \
	static class_name* _instance;                                                                   \
	static ReaderBase* CreateReaderInst();                                                          \
	virtual std::string GetReaderName();                                                            \
	virtual ANSYS_KEYWORD GetKeyWord();                                                             \
	void destroy_instance();																		\


#define IMPLEMENT_CDB_READER(class_name, card_type, card_txt)                                       \
class_name* class_name::_instance = nullptr;                                                        \
ReaderBase* class_name::CreateReaderInst() {                                                        \
	if (!_instance) { _instance = new class_name(CDBReader::Inst()); }                              \
	return _instance; }                                                                             \
void class_name::destroy_instance() {if(_instance){delete _instance;_instance = nullptr;}}							\
std::string class_name::GetReaderName() { return card_txt; }                                               \
ANSYS_KEYWORD class_name::GetKeyWord() { return card_type; }                                        \
bool bRegist_cdb_reader_##class_name = ReaderMgr::Inst()->Regist(class_name::CreateReaderInst());    \



